/**
 * @file lv_watch.h
 * Include all lv watch related headers
 */

#ifndef LV_WATCH_H
#define LV_WATCH_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#include "../lvgl/src/lv_draw/lv_draw_img_png_decoder.h"
#include "../lvgl/src/lv_draw/lv_draw_gif_player.h"
#include "../lvgl/src/lv_misc/lv_qrcode.h"
#include "../lvgl/src/lv_misc/lv_barcode.h"
#include "../lvgl/hal/hal.h"
#include "../lvgl/hal/hal_bt.h"
#include "../lvgl/hal/hal_ble.h"
#include "../lvgl/hal/hal_wlan.h"
#include "../lvgl/hal/hal_http.h"
#include "../lvgl/hal/md5/hal_md5.h"
#include "../lvgl/src/lv_misc/lv_debug.h"

#include "lv_objx/lv_watch_obj/lv_watch_obj.h"

#include "include/ui_textid.h"
#include "include/ui_activity_id.h"
#include "include/app_adaptor_interface.h"

#if LV_USE_MULTI_LANG
#include "framework/language/lv_lang.h"
#include "framework/language/lang_en.h"
#include "framework/language/lang_ch.h"
#include "framework/language/lang_ar.h"
#else
#include "framework/language/lv_i18n/lv_i18n_lang.h"
#endif

#include "include/ui_nvm_interface.h"
#include "include/ui_inter_msg_interface.h"
#include "include/watch_modemadp_interface.h"
#include "include/watch_bt_interface.h"
#include "include/watch_qq_interface.h"
#include "framework/message/watch_msg_handle.h"

#include "lv_watch_common.h"
#include "lv_watch_res.h"
#include "lv_theme_watch_night.h"
#include "lv_objx/lv_watch_slider/lv_watch_slider.h"
#include "lv_objx/lv_watch_tabview/lv_watch_tabview.h"
#include "lv_objx/lv_watch_list/lv_watch_list.h"

#include "lv_objx/lv_watch_activity_obj/lv_watch_activity_obj.h"

#include "lvgl/src/lv_font/lv_freetype.h"

#if USE_LV_WATCH_LAUNCHER != 0
#include "lv_apps/launcher/launcher.h"
#endif
#if USE_LV_WATCH_LAUNCHER2 != 0
#include "lv_apps/launcher2/launcher.h"
#endif
#include "lv_apps/dial/dial.h"
#include "lv_apps/dial/dial_switch.h"
#include "lv_apps/make_friends/make_friends.h"
#include "lv_apps/qrcode/qrcode.h"
#include "lv_apps/barcode/barcode.h"

#include "lv_apps/primary_menu/primary_menu.h"
#include "lv_apps/status_and_setting/status_and_setting.h"
#include "lv_apps/quick_function/quick_function.h"
#include "lv_apps/weather/weather.h"
#include "lv_apps/pedometer/pedometer.h"

#include "lv_apps/phonebook/phonebook.h"
#include "lv_apps/phone/phone.h"
#include "lv_apps/setting/setting.h"
#include "lv_apps/shutdown/shutdown.h"
#include "lv_apps/sos/sos.h"
#include "lv_apps/lowbattery/lowbattery.h"
#include "lv_apps/search/search.h"
#include "lv_apps/language/language.h"
#include "lv_apps/power_off_charging/power_off_charging.h"
#include "lv_apps/dialpad/dialpad.h"
#include "lv_apps/alarm/alarm.h"
#include "lv_apps/alarm/alarm_set.h"
#include "lv_apps/stopwatch/stopwatch.h"
#include "lv_apps/calculator/calculator.h"
#include "lv_apps/factory_mode/factory_mode.h"
#include "lv_apps/voice_msg/voice_msg.h"
#include "lv_apps/speech_recog/speech_recog.h"
#include "lv_apps/album/album.h"
#include "lv_apps/video_call/video_call.h"

#include "lv_apps/restart_and_reset/restart_and_reset.h"
#include "lv_apps/audio_player/audio_player.h"
#include "lv_apps/camera/camera.h"
#include "lv_apps/engineer_mode/engineer_mode.h"
#include "lv_apps/cta/cta.h"
#include "lv_apps/calendar/calendar.h"
#include "lv_apps/upgrade/upgrade.h"
#include "lv_apps/qrcode_scan/qrcode_scan.h"
#include "lv_apps/imgviewer/imgviewer.h"
#include "lv_apps/heart_rate/heart_rate.h"
#include "lv_apps/call_log/call_log.h"
#include "lv_apps/compass/compass.h"
#include "lv_apps/message/message.h"
#include "lv_apps/timer/timer_clock.h"
#include "lv_apps/exercise/exercise.h"
#include "lv_apps/sleep/sleep.h"
#include "lv_apps/elevation/elevation.h"
#include "lv_apps/activity/activity.h"
#include "lv_apps/exercise_record/exercise_record.h"
#include "lv_apps/search_phone/search_phone.h"
#include "lv_apps/qq/net/qq_net.h"
#include "lv_apps/qq/net/ui_net_interface.h"
#include "lv_apps/qq/net/qq_net_manager.h"
#include "lv_apps/qq/qq.h"

/*********************
 *      DEFINES
 *********************/
enum {
    WATCH_SUSPEND_INV,
    WATCH_SUSPEND_UI,
    WATCH_SUSPEND_KEY
};

#define WATCH_CHECK_SIM_STATUS_PERIOD    5000 //5s
#ifdef USE_WATCH_LITE
#define WATCH_HAS_WALLPAPER              0
#else
#define WATCH_HAS_WALLPAPER              1
#endif

/**********************
 *      TYPEDEFS
 **********************/
typedef struct {
    void * bg; /* background images */
    watch_dial_type_t dailtype;
} watch_info_t;

/**********************
 * GLOBAL PROTOTYPES
 **********************/
void watch_restart_req(void);
void watch_power_on_req(void);
void watch_default_set(void);

void * watch_get_bg(void);
void * watch_set_bg(const void * src);
void watch_set_dial_type(watch_dial_type_t dial_type);
extern lv_task_t * lowbattery_task_p;
#if USE_LV_WATCH_SIMCHECK
extern lv_task_t * checksim_task_p;
#endif
extern TASK_HANDLE *gui_task_id;
extern TASK_HANDLE *modem_adp_task_id;
extern phone_call_params_t  call_params;
extern bool gcf_test;

uint32_t time_to_seconds(const hal_rtc_t * tm);
void seconds_to_time(int32_t tim, hal_rtc_t * tm);
uint8_t rtc_calc_weekday(hal_rtc_t * tm);
void watch_wake_up(bool wakeup_dev);
void watch_wakeup_time_reset(void);
bool watch_is_ready(void);
void watch_set_ready_state(bool ready_flag);
void watch_suspend(lv_task_t * task);
void watch_set_suspend_enable(bool enable, lv_watch_Activity_Id_t act, bool top);
void watch_poweron_logo(void);
void watch_low_power_ind_cb(void * para);
void watch_low_power_ind_proc(uint32_t bat_percent);
void watch_set_sleep_lcd_only(bool enable);
bool watch_get_sleep_lcd_only(void);
bool watch_get_lcd_status(void);
void watch_set_lcd_status(bool wakeup);
uint32_t watch_indev_get_inactive_time(const lv_indev_t * indev);
void watch_suspend_by_key(void);
void watch_suspend_by_ui(void);
void qrcode_create_event_cb(lv_obj_t * btn, lv_event_t event);
void watch_set_pintype(MMI_MODEM_PIN_STATUS_TYPE pinreqtype);
MMI_MODEM_PIN_STATUS_TYPE watch_get_pintype(void);
void watch_wakeup_lcd(bool always);
void watch_set_alarm_flag(bool alarm_flag);
void watch_disable_wakeup_lcd(void);
/**********************
 *      MACROS
 **********************/

#ifdef __cplusplus
}
#endif

#endif /*LV_WATCH_H*/
